home *** CD-ROM | disk | FTP | other *** search
/ Merciful 1 / Merciful - Disc 1.iso / software / g / gvp_faaast_prep / gvpfaastprep.dms / gvpfaastprep.adf / ScsiExamples / ScsiExamples.lzh / ReadCapacity.c < prev    next >
C/C++ Source or Header  |  1990-07-05  |  4KB  |  160 lines

  1. /*
  2. ** ReadCapacity.c - read a drive's capacity using HD_SCSICMD
  3. ** Copyright (C) 1990 by Ralph Babel, Falkenweg 3, D-6204 Taunusstein, FRG
  4. ** all rights reserved - alle Rechte vorbehalten
  5. **
  6. ** 02-Jun-1990 created
  7. */
  8.  
  9. /*** included files ***/
  10.  
  11. #include <exec/types.h>
  12. #include <exec/io.h>
  13. #include <exec/memory.h>
  14. #include <devices/scsidisk.h>
  15. #include <libraries/dos.h>
  16. #include <proto/exec.h>
  17. #include <proto/dos.h>
  18.  
  19. /*** external symbol references ***/
  20.  
  21. void fprintf(BPTR, const char *, ...);
  22.  
  23. /*** constants ***/
  24.  
  25. #define BOARD 0 /* controller board */
  26. #define TID   0 /* SCSI target ID */
  27. #define LUN   0 /* logical unit */
  28.  
  29. #define UNIT (BOARD * 100 + LUN * 10 + TID)
  30.  
  31. #define MAXBUF 252
  32.  
  33. /*** structures ***/
  34.  
  35. struct CapacityData
  36.  {
  37.  ULONG HighSector;
  38.  ULONG SectorSize;
  39.  };
  40.  
  41. /*** entry point (RXStartUp.obj) ***/
  42.  
  43. void __stdargs __saveds main(
  44. ULONG argc,
  45. const char *const argv[])
  46.  {
  47.  BPTR fh;
  48.  UBYTE *sensedata;
  49.  struct MsgPort *mp;
  50.  struct IOStdReq *io;
  51.  struct CapacityData *cd;
  52.  struct SCSICmd SC;
  53.  UBYTE command[10];
  54.  
  55.  if(argc != 0) /* CLI only! */
  56.   {
  57.   fh = Output();
  58.  
  59.   if((cd = AllocMem(sizeof(struct CapacityData), MEMF_CHIP)) != NULL)
  60.    {
  61.    if((sensedata = AllocMem(MAXBUF, MEMF_CHIP)) != NULL)
  62.     {
  63.     if((mp = CreatePort(NULL, 0)) != NULL)
  64.      {
  65.      if((io = CreateStdIO(mp)) != NULL)
  66.       {
  67.       if(OpenDevice("gvpscsi.device", UNIT, (struct IORequest *)io, 0) == 0)
  68.        {
  69.        io->io_Command = HD_SCSICMD;
  70.        io->io_Length  = sizeof(struct SCSICmd);
  71.        io->io_Data    = (APTR)&SC;
  72.  
  73.        SC.scsi_Data        = (UWORD *)cd;
  74.        SC.scsi_Length      = sizeof(struct CapacityData);
  75.        SC.scsi_Command     = command;
  76.        SC.scsi_CmdLength   = 6;
  77.  
  78. #ifdef SCSIF_AUTOSENSE
  79.  
  80.        SC.scsi_Flags       = SCSIF_READ | SCSIF_AUTOSENSE;
  81.        SC.scsi_SenseData   = sensedata;
  82.        SC.scsi_SenseLength = MAXBUF;
  83.        SC.scsi_SenseActual = 0;
  84.  
  85. #else
  86.  
  87.        SC.scsi_Flags       = SCSIF_READ;
  88.  
  89. #endif
  90.  
  91.        command[0] = 0x25; /* READ CAPACITY */
  92.        command[1] = LUN << 5;
  93.        command[2] = 0;
  94.        command[3] = 0;
  95.        command[4] = 0;
  96.        command[5] = 0;
  97.        command[6] = 0;
  98.        command[7] = 0;
  99.        command[8] = 0;
  100.        command[9] = 0;
  101.  
  102.        (void)DoIO((struct IORequest *)io);
  103.  
  104.        fprintf(fh, "io_Error         = %d\n",  io->io_Error);
  105.        fprintf(fh, "scsi_Status      = %d\n",  SC.scsi_Status);
  106.        fprintf(fh, "scsi_CmdActual   = %d\n",  SC.scsi_CmdActual);
  107.        fprintf(fh, "scsi_Actual      = %ld\n", SC.scsi_Actual);
  108.  
  109. #ifdef SCSIF_AUTOSENSE
  110.  
  111.        fprintf(fh, "scsi_SenseActual = %d\n",  SC.scsi_SenseActual);
  112.  
  113.        if(SC.scsi_SenseActual != 0)
  114.         {
  115.         UWORD i;
  116.  
  117.         fprintf(fh, "\nSenseData:");
  118.  
  119.         for(i = 0; i < SC.scsi_SenseActual; ++i)
  120.          fprintf(fh, " %02x", sensedata[i]);
  121.  
  122.         fprintf(fh, "\n");
  123.         }
  124.  
  125. #endif
  126.  
  127.        if(io->io_Error == 0)
  128.         {
  129.         fprintf(fh, "\nHighSector = %ld\n", cd->HighSector);
  130.         fprintf(fh, "SectorSize = %ld\n",   cd->SectorSize);
  131.         }
  132.  
  133.        CloseDevice((struct IORequest *)io);
  134.        }
  135.       else
  136.        fprintf(fh, "Error %d while opening SCSI unit %ld.\n",
  137.         io->io_Error, (long)UNIT);
  138.  
  139.       DeleteStdIO(io);
  140.       }
  141.      else
  142.       fprintf(fh, "Could not create I/O request.\n");
  143.  
  144.      DeletePort(mp);
  145.      }
  146.     else
  147.      fprintf(fh, "Could not create message port.\n");
  148.  
  149.     FreeMem(sensedata, MAXBUF);
  150.     }
  151.    else
  152.     fprintf(fh, "Insufficient free store.\n");
  153.  
  154.    FreeMem(cd, sizeof(struct CapacityData));
  155.    }
  156.   else
  157.    fprintf(fh, "Insufficient free store.\n");
  158.   }
  159.  }
  160.